/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author simone
 */
@Entity
@Table(name = "Tipo_viaggio")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Tipoviaggio.findAll", query = "SELECT t FROM Tipoviaggio t"),
    @NamedQuery(name = "Tipoviaggio.findByIdTipoViaggio", query = "SELECT t FROM Tipoviaggio t WHERE t.idTipoViaggio = :idTipoViaggio"),
    @NamedQuery(name = "Tipoviaggio.findByName", query = "SELECT t FROM Tipoviaggio t WHERE t.name = :name")})
public class Tipoviaggio implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_tipo_viaggio")
    private Integer idTipoViaggio;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fkTipoViaggio")
    private Collection<Viaggio> viaggioCollection;

    public Tipoviaggio() {
    }

    public Tipoviaggio(Integer idTipoViaggio) {
        this.idTipoViaggio = idTipoViaggio;
    }

    public Tipoviaggio(Integer idTipoViaggio, String name) {
        this.idTipoViaggio = idTipoViaggio;
        this.name = name;
    }

    public Integer getIdTipoViaggio() {
        return idTipoViaggio;
    }

    public void setIdTipoViaggio(Integer idTipoViaggio) {
        this.idTipoViaggio = idTipoViaggio;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Viaggio> getViaggioCollection() {
        return viaggioCollection;
    }

    public void setViaggioCollection(Collection<Viaggio> viaggioCollection) {
        this.viaggioCollection = viaggioCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idTipoViaggio != null ? idTipoViaggio.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Tipoviaggio)) {
            return false;
        }
        Tipoviaggio other = (Tipoviaggio) object;
        if ((this.idTipoViaggio == null && other.idTipoViaggio != null) || (this.idTipoViaggio != null && !this.idTipoViaggio.equals(other.idTipoViaggio))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ejb.entities.Tipoviaggio[ idTipoViaggio=" + idTipoViaggio + " ]";
    }
    
}
